<template>
  <view class="navigation">
    <view class="left">
      <view class="item">
        <u-icon
          name="server-fill"
          :size="40"
          :color="$u.color['contentColor']"
        ></u-icon>
        <view class="text u-line-1">联系客服</view>
      </view>
      <navigator url="/pages/cart/cart" open-type="switchTab" class="item car">
        <u-badge
          class="car-num"
          :count="cartCount"
          type="error"
          :offset="[-3, -6]"
        ></u-badge>
        <u-icon
          name="shopping-cart"
          :size="40"
          :color="$u.color['contentColor']"
        ></u-icon>
        <view class="text u-line-1">购物车</view>
      </navigator>
    </view>
    <view class="right">
      <view class="cart btn u-line-1" @click="handleGoodsAdd">加入购物车</view>
      <view class="buy btn u-line-1">立即购买</view>
    </view>
  </view>
</template>

<script>
import { mapMutations, mapGetters } from "vuex";
export default {
  props: {
    goodsInfo: {
      type: Object,
    },
  },
  computed: {
    ...mapGetters("cart", ["cartCount"]),
  },
  methods: {
    ...mapMutations("cart", ["cartAdd"]),
    handleGoodsAdd() {
      this.cartAdd({ value: this.goodsInfo });
      uni.showToast({
        title: "添加成功",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.navigation {
  display: flex;
  border: solid 2rpx #f2f2f2;
  background-color: #ffffff;
  padding: 16rpx 0;
  height: 94rpx;
  .left {
    display: flex;
    font-size: 20rpx;
    margin-left: 20rpx;
    text-align: center;
    .item {
      margin: 0 30rpx;
      &.car {
        text-align: center;
        position: relative;
        .car-num {
          position: absolute;
          top: -10rpx;
          right: -10rpx;
        }
      }
    }
  }
  .right {
    display: flex;
    align-items: center;
    .btn {
      line-height: 60rpx;
      text-align: center;
      padding: 0 30rpx;
      border-radius: 36rpx;
      color: #ffffff;
      font-size: 26rpx;
      width: 196rpx;
      height: 60rpx;
    }
    .cart {
      background-color: #fcaa23;
      margin-right: 24rpx;
      margin-left: 20rpx;
    }
    .buy {
      background-color: #ea4350;
    }
  }
}
</style>
